﻿using IHISCETeim.BLL;
using IHISCETeim.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using IHISCETeim.Library;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace IHISCETeim.Web.AgentSys.VipMgr
{
    public partial class VIPCustomerExchangeView : AgentPageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.VIP积分兑换_回访, Permission.查看 };
            }
        }
        protected override string DWZRef
        {
            get { return "VIPCustomerExchangeList"; }

        }

        protected int CustExID
        {
            get
            {
                return GetRequestValue<int>("CustExID", 0);
            }
        }
        private VIPCustomerExchangeInfo _vipObj = null;
        protected VIPCustomerExchangeInfo vipObj
        {
            get
            {
                if (_vipObj == null)
                    _vipObj = VIPCustomerExchangeController.GetList(CustExID);

                return _vipObj;
            }
        }

        private List<VIPCustomerExchangeDetailInfo> _listDetail = null;
        protected List<VIPCustomerExchangeDetailInfo> listDetail
        {
            get
            {
                if (_listDetail == null)
                    _listDetail = VIPCustomerExchangeController.GetAllDetail(CustExID);

                return _listDetail;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "ADD")
            {
                ADD();//
            }
            else
            { 
            bind();
            }
        }

        private void bind()
        {
            this.rpDetail.DataSource = listDetail;
            this.rpDetail.DataBind();
        }

        private void ADD()
        {
            if (!HasPower(IHISCETeim.Web.Permission.VIP积分兑换_回访) )
            {
                ErrorJson("你没有权限进行此操作");
                return;
            }
            bool IsVisit = GetRequestValue<bool>("IsVisit", false);
            DateTime VisitDate = GetRequestValue<DateTime>("VisitDate", DateTime.Now);
            string VisitRemark = GetRequestValue<string>("VisitRemark", "");
            bool b = VIPCustomerExchangeController.UpdateVisit(CustExID, IsVisit, VisitDate, VisitRemark);
            if (b)
            {
                SuccessJson("已成功对此积分兑换进行回访.",DWZRef);
            }
            else
            {
                ErrorJson("处理回访信息失败");
            }
        }
    }
}